home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-30 | 11.0 KB | 456 lines | [TEXT/IGR0] |
- #pragma rtglobals=1
-
- #include <Strings as Lists>
-
- | NOTE: This procedure file requires that the MDInterpolator XOP be installed
- | in the Igor Extensions folder.
- |
- | For a demonstration experiment showing how this procedure file is used,
- | see the experiment file "Path Profile Demo" in the Graphs subfolder of the
- | Examples folder in your Igor Pro folder.
- |
- | These procedures are written to be used with the control panel that is made by
- | the procedure file. The functions that do the actual work could be used by themselves
- | if you did some work to modify them, or to set up the data folders and global variables
- | that the procedures need.
- |
- | Possible Improvements:
- | Make it work with Images and Contour Plots that aren't displayed on Left and Bottom axes.
-
- Menu "Macros"
- "Profile Control Panel", MakeProfilePanel()
- end
-
- Proc MakeProfilePanel()
-
- Silent 1
-
- String SaveFolder=GetDataFolder(1)
- SetDataFolder root:
-
- | Test for private data folder for these procedures, make it if it doesn't exist
-
- if (DataFolderExists("root:Packages")==0)
- NewDataFolder/S Packages
- NewDataFolder/S WMProfileProc
- else
- SetDataFolder Packages
- if (DataFolderExists("WMProfileProc")==0)
- NewDataFolder/S WMProfileProc
- else
- SetDataFolder WMProfileProc
- endif
- endif
-
- | Some globals used by these procedures
-
- Variable/G PR_NumProfPoints=100
- String/G PR_PathXName="PathXWave"
- String/G PR_PathYName="PathYWave"
- String/G PR_OutWaveName="ProfileWave"
- SetDataFolder $SaveFolder
-
- if (wintype("ProfilePanel") == 7)
- DoWindow/F ProfilePanel
- else
- ProfilePanel()
- endif
- end
-
- | The function that actually calculates the profile data
-
- Function InterpPath(Wave2D, PathY, PathX, NumOutPnts, OutName, AtPoints)
- Wave Wave2D, PathY, PathX
- Variable NumOutPnts
- String OutName
- Variable AtPoints
-
- | String OutName=UniqueName(NameofWave(Wave2D)+"_path", 1, 0)
- | print "Wave containing path is ", OutName
-
- Variable TotalLength,LengthInc, LengthP, PointX, PointY,Distance
- Variable/C Point
- Variable ind, endloop
- Variable XVal, YVal
- Variable hasX=waveExists(PathX)
-
- | print "InterpPath: hasX = ", hasX
-
- if (AtPoints)
- NumOutPnts = numpnts(PathY)
- endif
- Make/O/N=(NumOutPnts) $OutName
- Wave w=$OutName
- Duplicate/O PathY, root:Packages:WMProfileProc:PR_LineLength
- Wave PR_LineLength=root:Packages:WMProfileProc:PR_LineLength
-
- if (AtPoints)
- ind = 0
- endloop=NumOutPnts
- do
- if (hasX)
- XVal = PathX[ind]
- else
- XVal = pnt2x(pathY, ind)
- endif
- // interp2d is in the MDInterpolator XOP.
- // If you get an error here, put an alias to MDInterpolator in Igor Extensions and relaunch Igor.
- w[ind] = interp2d(wave2D, XVal, pathY[ind])
- ind += 1
- while(ind<endloop)
- else
- TotalLength=WaveLineLengthXY(PathX, PathY, PR_LineLength)
- | print "TotalLength",TotalLength
- LengthInc = TotalLength/(NumOutPnts-1)
- SetScale/I x 0,TotalLength,$OutName
-
- ind=0
- endloop=NumOutPnts
- do
- Distance=ind*LengthInc
- | print "ProfileProc: distance = ", distance
- Point=XYatDistance(PR_LineLength, PathX, PathY, Distance)
- | print "ProfileProc: point, ind:",point, ind
- w[ind] = interp2d(Wave2D, real(Point), imag(Point))
- | print point, ind, w[ind]
-
- ind += 1
- while(ind< endloop)
- endif
-
- KillWaves PR_LineLength
- end
-
- | XYatDistance calculates the X, Y points corresponding to a distance along the wave, or pair of waves.
- | If XWave doesn't exist, does a waveform calculation, if it does exist, does XY calculation.
- |
- | Requires that WaveLineLengthXY be run first to calculate the line length wave.
-
- Function/C XYatDistance(LengthWave, XWave, YWave, Distance)
- Wave LengthWave, XWave, YWave
- Variable/D Distance
-
- Variable hasX = waveExists(XWave)
-
- | print "XYatDistance: hasX = ", hasX
-
- Variable i=0, PNum, TP=numpnts(LengthWave), Px, Py
- Variable XVal0, XVal1
-
- do
- | print "XYatDistance, d, LW[i]:",Distance, LengthWave[i]
- if (Distance < LengthWave[i])
- PNum=i-1
- break
- endif
-
- i += 1
- while (i < TP)
-
- if (i > TP)
- | print "XYatDistance: i > TP"
- return(cmplx(NaN, NaN))
- endif
-
- Distance -= LengthWave[PNum]
- Distance = Distance/(LengthWave[PNum+1]-LengthWave[PNum])
-
- if (hasX)
- Xval0 = XWave[PNum]
- Xval1 = XWave[PNum+1]
- else
- Xval0 = pnt2x(YWave, PNum)
- Xval1 = pnt2x(YWave, PNum+1)
- endif
-
- Px = Xval0 + Distance*(Xval1-Xval0)
- Py = YWave[PNum] + Distance*(YWave[PNum+1]-YWave[PNum])
-
- return cmplx(Px, Py)
- end
-
- | WaveLineLengthXY calculates a new wave with line length along the wave or wave pair.
- | Each element in the calculated wave is the total length of the given wave(s) up to the
- | corresponding element.
-
- Function/D WaveLineLengthXY(InWaveX, InWaveY, LengthWave)
- Wave InWaveX, InWaveY, LengthWave
-
- Variable hasX=waveExists(InWaveX)
- Variable Xval0, Xval1
-
- | print "WaveLineLengthXY: hasX = ", hasX
-
- if (hasX)
- if (numpnts(InWaveX) != numpnts(InWaveY))
- | print "WaveLineLengthXY: wrong X points"
- return NaN
- endif
- endif
-
- if (numpnts(InWaveY) != numpnts(LengthWave))
- | print "WaveLineLengthXY: wrong LengthWave"
- return NaN
- endif
-
- Variable/D Sum=0
- Variable i=0, numiters=numpnts(InWaveY)-1
-
- LengthWave[0] = 0
- do
- if (hasX)
- Xval0 = InWaveX[i]
- Xval1 = InWaveX[i+1]
- else
- Xval0 = pnt2x(InWaveY, i)
- Xval1 = pnt2x(InWaveY, i+1)
- endif
-
- sum += sqrt((Xval1-Xval0)^2 + (InWaveY[i+1]-InWaveY[i])^2)
- LengthWave[i+1] = sum
-
- i += 1
- while (i<numiters)
-
- return sum
- end
-
-
- | ListContoursImages() returns a string containing the names of both images and
- | contour plots. Eliminates duplicate names.
-
- Function/S ListContoursImages()
-
- String ContourList=ContourNameList("",";")
- String ImageList=ImageNameList("",";")
- String Name1, Name2
- Variable i1=0, i2, Match
-
- i1 = 0
- do
- Name1=GetStrFromList(ImageList, i1, ";")
- if (strlen(Name1) == 0)
- break
- endif
- i2 = 0
- do
- Name2 = GetStrFromList(ContourList, i2, ";")
- if (strlen(Name2) == 0)
- break
- endif
- if (cmpstr(Name1, Name2) == 0)
- Match = 1
- break
- else
- Match = 0
- endif
- i2 += 1
- while(1)
- if (Match == 0)
- ContourList += Name1+";"
- endif
- i1 += 1
- while (1)
-
- return ContourList
- end
-
- |***************************
- | Action procedures for controls follow
- |***************************
-
- Function MakePathProc(ctrlName) : ButtonControl
- String ctrlName
-
- SVAR PathXName=root:Packages:WMProfileProc:PR_PathXName
- SVAR PathYName=root:Packages:WMProfileProc:PR_PathYName
- | NVAR HasPathXWave=root:Packages:WMProfileProc:HasPathXWave
-
- Variable hasX
-
- | print "X,Y:", PathXName, PathYName
-
- if (strlen(PathYName) == 0)
- Abort "No name for Y path wave"
- endif
- if (strlen(PathXName) == 0)
- Abort "No name for X path wave"
- endif
-
- Make/O/N=2 $PathXName
- wave PR_XWave=$PathXName
- Make/O/N=2 $PathYName
- wave PR_YWave=$PathYName
-
-
- GetAxis bottom
-
- | print V_min, V_max
- PR_XWave[0] = V_min
- PR_XWave[1] = V_max
-
- GetAxis left
- | print V_min, V_max
- PR_YWave[0] = V_min
- PR_YWave[1] = V_max
-
- AppendToGraph $PathYName vs $PathXName
- ControlUpdate PathWavePopup
- String traceList=traceNameList("", ";",1)
- | print traceList
-
- String currentName
- Variable i=0
- do
- currentName=GetStrFromList(traceList, i,";")
- | print currentName
- if (strlen(currentName)== 0)
- break
- endif
- if (cmpstr(currentName, PathYName) == 0)
- PopupMenu PathWavePopup,mode=i+1
- break
- endif
-
- i += 1
- while (1)
-
- End
-
- Function EditPathProc(ctrlName) : ButtonControl
- String ctrlName
-
- String TraceName
-
- ControlInfo PathWavePopup
- TraceName=S_value
-
- Wave PathY = TraceNameToWaveRef("", TraceName)
- | print "PathY = ", NameofWave(PathY)
- Wave PathX = XWaveRefFromTrace("", TraceName)
- | print "PathX = ", NameofWave(PathX)
-
- if (WaveExists(PathY) == 0)
- Abort "Path Y wave doesn't exist"
- endif
- if (WaveExists(PathX) == 0)
- Abort "Please do not edit Waveform traces, only XY traces"
- endif
-
-
- String Window=WinName(0,1)
-
- DoWindow/F $Window
- ShowTools
-
- | print "Print from pathWaves:", PathY[0], PathX[0]
- GraphWaveEdit $TraceName
-
- End
-
- Function ProfileProc(ctrlName) : ButtonControl
- String ctrlName
-
- SVAR PR_OutWaveName=root:Packages:WMProfileProc:PR_OutWaveName
-
- NVAR PR_NumProfPoints=root:Packages:WMProfileProc:PR_NumProfPoints
-
- String ContourList=ContourNameList("",";")
- String ContourName, PathName
- Variable AtPoints
-
- ContourName=GetStrFromList(ContourList, 0, ";")
- if (strlen(ContourName) == 0)
- ContourList = ImageNameList("",";")
- ContourName = GetStrFromList(ContourList, 0, ";")
- if (strlen(ContourName) == 0)
- abort "No contour plot or image found in the top graph window"
- else
- Wave Wave2d=ImageNameToWaveRef("", ContourName)
- endif
- else
- | print "ContourName = ", ContourName
- Wave Wave2d=ContourNameToWaveRef("", ContourName)
- endif
-
- ControlInfo PathWavePopup
- PathName = S_value
-
- Wave PathY = TraceNameToWaveRef("",PathName)
- Wave PathX = XWaveRefFromTrace("",PathName)
-
- ControlInfo AtPointsCheck
- AtPoints=V_value
-
- InterpPath(Wave2D, PathY, PathX, PR_NumProfPoints, PR_OutWaveName, AtPoints)
-
- End
-
-
-
-
- Function ProfileGraphProc(ctrlName) : ButtonControl
- String ctrlName
-
- SVAR PR_OutWaveName=root:Packages:WMProfileProc:PR_OutWaveName
-
- Display $PR_OutWaveName
-
- End
-
-
- Function InterpCheckProc(ctrlName,checked) : CheckBoxControl
- String ctrlName
- Variable checked
-
- if (checked)
- Checkbox AtPointsCheck, value=0
- else
- Checkbox AtPointsCheck, value=1
- endif
-
- End
-
- Function ProfileCheckProc(ctrlName,checked) : CheckBoxControl
- String ctrlName
- Variable checked
- Variable CtrlProfChk, CtrlInterpChk
-
- if (checked)
- Checkbox InterpPathCheck, value=0
- else
- Checkbox InterpPathCheck, value=1
- endif
-
-
- End
-
- |*******************************
- | Recreation macro for profile control panel
- |*******************************
-
- Proc ProfilePanel()
- PauseUpdate; Silent 1 | building window...
- NewPanel /W=(273,41,541,334)
- SetDrawLayer UserBack
- DrawRect 36,33,228,106
- DrawRect 23,142,245,188
- SetVariable SetXPathWave,pos={48,38},size={169,17},title="X Path Name:"
- SetVariable SetXPathWave,limits={-INF,INF,1},value= root:Packages:WMProfileProc:PR_PathXName
- SetVariable SetYPathWave,pos={48,57},size={169,17},title="Y Path Name:"
- SetVariable SetYPathWave,limits={-INF,INF,1},value= root:Packages:WMProfileProc:PR_PathYName
- Button MakePathButton,pos={90,81},size={83,20},proc=MakePathProc,title="Make Path"
- Button EditPathButton,pos={91,110},size={83,20},proc=EditPathProc,title="Edit Path"
- Button ProfileButton,pos={44,250},size={83,20},proc=ProfileProc,title="Do Profile"
- Button ProfileGraphButton,pos={137,250},size={83,20},proc=ProfileGraphProc,title="Graph"
- SetVariable setvar0,pos={28,195},size={216,17},title="Number of Points"
- SetVariable setvar0,limits={0,INF,1},value= root:Packages:WMProfileProc:PR_NumProfPoints
- SetVariable SetOutWaveName,pos={28,230},size={217,17},title="Output Wave Name"
- SetVariable SetOutWaveName,limits={-INF,INF,1},value= root:Packages:WMProfileProc:PR_OutWaveName
- PopupMenu PathWavePopup,pos={51,6},size={149,19},title="Path trace:"
- PopupMenu PathWavePopup,mode=6,value= #"TraceNameList(\"\",\";\",1)"
- CheckBox InterpPathCheck,pos={29,144},size={177,20},proc=InterpCheckProc,title="Interpolate along path",value=1
- CheckBox AtPointsCheck,pos={29,163},size={202,20},proc=ProfileCheckProc,title="Profile at path wave points",value=0
- EndMacro
-
-